package functions

import (
	"chat-room/common"
	"chat-room/server/global"
	"encoding/json"
	"net"
)

type Functions struct {

}

//登录成功后往 global.AllLoginMap 加入数据
func (that *Functions) AppendLoginMap(conn net.Conn, name string){
	global.AllLoginMap.Store(conn,name)
}

//组合系统消息发送数据结构体的切片
func (that *Functions) MakeSystemMsgStruct(str string) (messageExByte []byte, err error) {
	SystemMsgEx := common.SystemMsg{Info:str}

	//转成json切片
	loginResponseMsgExByte, err := json.Marshal(SystemMsgEx)
	if err != nil {
		return
	}
	//传递消息结构体
	messageEx := &common.Message{
		Type: common.SystemMsgType,
		Data: string(loginResponseMsgExByte),
	}
	//转成json切片
	messageExByte, err = json.Marshal(messageEx)
	if err != nil {
		return
	}
	return
}